#!/bin/bash
FILEWITHEXT="$1"
FILEBASENAME="${FILEWITHEXT##*/}"
FNAME="${FILEBASENAME%.*}"

if [ "x${1}" == "x" ]
then
  echo "no file given, use as $0 file_to_convert.dv"
  exit 2
fi

if [ "x${1}" == "x${FNAME}.mp4" ]
then
  echo "writing to same file?"
  FNAME="${FNAME}_new"
fi

if [ -f "${FNAME}.mp4" ]
then
  echo "file already encoded"
  exit 3
fi
echo $FNAME
ffmpeg -y -i "$1" -map 0:v:0 -map 0:a:0 \
  -vf pp=lb \
  -vcodec libx264 -x264opts "force-cfr:chroma-qp-offset=2" \
  -sn -g 50 -preset:v slower -movflags +faststart \
  -af aresample=min_hard_comp=0.1 -pix_fmt yuv420p \
  -acodec libaacplus -ac 2 -ab 64k -ar 48k \
  "$FNAME.mp4"
#-x265-params "keyint=50"
#-x265-paopts "force-cfr:chroma-qp-offset=2"
